using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;

namespace SideShow.Scf.ObjectModel
{
    [Serializable]
    public enum ScfAlignment
    {
        [XmlEnum("l")]
        Left,
        [XmlEnum("r")]
        Right,
        [XmlEnum("c")]
        Center
    }

    [Serializable]
    public enum ScfImageFit
    {
        [XmlEnum("native")]
        Native,
        [XmlEnum("width")]
        Width,
        [XmlEnum("screen")]
        Screen,
        [XmlEnum("auto")]
        Auto
    }

    [Serializable]
    public class ScfImage : ScfObject
    {
        private uint _id;
        private ScfAlignment _alignment;
        private ScfImageFit _imageFit;
        private string _alternateText = string.Empty;

        public uint Id
        {
            get { return _id; }
            set { _id = value; }
        }

        public ScfAlignment Alignment
        {
            get { return _alignment; }
            set { _alignment = value; }
        }

        public ScfImageFit ImageFit
        {
            get { return _imageFit; }
            set { _imageFit = value; }
        }

        public string AlternateText
        {
            get { return _alternateText; }
            set { _alternateText = value; }
        }

        protected internal override void DeserializeFromXml(System.Xml.XmlNode node)
        {
            base.DeserializeFromXml(node);
            _id = GetAttribute<uint>(node, "id");
            _alignment = GetAttribute<ScfAlignment>(node, "align");
            _imageFit = GetAttribute<ScfImageFit>(node, "fit");
            _alternateText = GetAttribute<string>(node, "alt", string.Empty);
        }

        protected internal override void SerializeObject(System.IO.BinaryWriter writer)
        {
            base.SerializeObject(writer);
            writer.Write(_id);
            writer.Write((int)_alignment);
            writer.Write((int)_imageFit);
            writer.Write(_alternateText ?? string.Empty);
        }

        protected internal override void DeserializeObject(System.IO.BinaryReader reader)
        {
            base.DeserializeObject(reader);
            _id = reader.ReadUInt32();
            _alignment = (ScfAlignment)reader.ReadInt32();
            _imageFit = (ScfImageFit)reader.ReadInt32();
            _alternateText = reader.ReadString();
        }
    }
}
